#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<unordered_set>
using namespace std;

class Solution {
public:
    int longestOnes(vector<int>& nums, int k) {
        int ret = 0, n = nums.size(), count = 0;
        for (int left = 0, right = 0; right < n; right++) {
            if (nums[right] == 0) count++;
            while (count > k) {
                if (nums[left++] == 0) count--;
            }
            ret = max(ret, right - left + 1);
        }
        return ret;
    }
};

class Solution {
public:
    vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
        vector<int> ret;
        unordered_set<int> hash(nums1.begin(), nums1.end());
        for (int i = 0; i < nums2.size(); i++) {
            if (hash.find(nums2[i]) != hash.end()) {
                ret.push_back(nums2[i]);
                hash.erase(nums2[i]);
            }
        }

        return ret;
    }
};